package normalapi;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimaDemo {
    public static void main(String[] args) {
        System.out.println(0.09 + 0.01);//0.09999999999999999
        BigDecimal num = new BigDecimal("0.09").add(new BigDecimal("0.01"));
        System.out.println(num);
        //通过静态方法获取
        BigDecimal num2 = BigDecimal.valueOf(0.09).add(BigDecimal.valueOf(0.01));
        System.out.println(num2);
        //BigDecimal 常用方法
        //add 加
        BigDecimal num3 = num.add(num2);
        //subtract 减
        BigDecimal num4 = num.subtract(num2);
        //multiply 乘
        BigDecimal num5 = num.multiply(num2);
        //divide 除,第二个参数为小数位数，第三个参数为舍入模式（四舍五入）RoundingMode枚举值 HALF_UP 向上取整 HALF_DOWN 向下取整
        BigDecimal num6 = num.divide(num2,2, RoundingMode.HALF_UP);
        //remainder 取余
        BigDecimal num7 = num.remainder(num2);
        //除余
        BigDecimal[] num71 = num.divideAndRemainder(num2);
        System.out.println("商："+num71[0]+" 余数："+num71[1]);
    }
}
